package Java常用算法练习;

/**
 * Created by dell on 2017/5/9.
 */
public class Lian {
   private void calcByEnum(int num,int off,float fPercent) { // 学生人数，上下波动人数，就业率
      float fMinDiff = 1.0f, fTmp;
      int Realnum = 300;//学生总人数
      for (int i = num - off + 1; i <= num + off; i++) {  //对每个人进行列举
         fTmp = Math.abs(Math.round(i * fPercent) / (float) i - fPercent);
         if (fTmp < fMinDiff) {
            fTmp = fMinDiff;
            Realnum = i;
         }
         int jiuye = Math.round(Realnum * fPercent);//就业学生人数
         System.out.println("通过枚举，计算出学生总人数是：" + Realnum);
         System.out.println("已就业学生人数为：" + jiuye);
         System.out.println("问题陈述给的就业率为：" + fPercent * 100 + "%");
         System.out.println("计算结果对应的就业率为：" + (jiuye / (float) Realnum) * 100 + "%");
      }
   }
      public static void main(String[] args) {
         Lian obj=new Lian();
         obj.calcByEnum(300,20,0.8323f);

   }
}

